package booklib.util;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 数据库工具类
 * @author yaer
 *
 */
public class DbUtil {
	private String dbUrl="jdbc:sqlserver://localhost:1433;DatabaseName=db_book";
	private String dbName="sa";
	private String dbPassword="123456";

	private String jdbcName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	public Connection getCon()throws Exception{

		Class.forName(jdbcName);
		Connection con=DriverManager.getConnection(dbUrl,dbName,dbPassword);
		return con;
		
	}
	public void closeCon(Connection con)throws Exception{
		if(con!=null){
			con.close();
		}
	}
	public static void main(String[] args) {
		DbUtil dbUtil=new DbUtil();
		try{
			dbUtil.getCon();
			System.out.println("数据库链接成功");
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("数据库链接失败");
		}
	}
}
